<template>
  <el-tree
    ref="tree"
    :data="menus"
    :props="defaultProps"
    :expand-on-click-node="false"
    node-key="catId"
    :default-expanded-keys="expandedKey"
    @node-click="nodeclick"
  >
  </el-tree>
</template>

<script>
  export default {
    name: "category",
    data() {
      return {
        menus: [],
        // 默认要展开的菜单
        expandedKey: [],
        defaultProps: {
          children: "children",
          label: "name",
        },
      };
    },
    methods: {
      nodeclick(data, node, component) {
        this.$emit("tree-node-click", data, node, component)

      },
      getMenus() {
        this.$http({
          url: this.$http.adornUrl("/product/category/list/tree"),
          method: "get",
        }).then(({data}) => {
          console.log(data.data);
          this.menus = data.data;
        });
      },
    },
    created() {
      this.getMenus();
    },
  }
</script>

<style scoped>

</style>
